package com.twetec.cms.service.statistic.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.twetec.cms.dao.mapper.statistic.StatisticSitePageViewsMapper;
import com.twetec.cms.model.po.statistic.StatisticSitePageViewsPO;
import com.twetec.cms.service.statistic.StatisticSitePageViewsService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZCZ
 * @since 2022-03-05
 */
@Service
public class StatisticSitePageViewsServiceImpl extends ServiceImpl<StatisticSitePageViewsMapper, StatisticSitePageViewsPO> implements StatisticSitePageViewsService {

    @Override
    public List<StatisticSitePageViewsPO> pageViewCount(Date gmtStartTime, Date gmtEndTime) {
        QueryWrapper<StatisticSitePageViewsPO> queryWrapper = new QueryWrapper<>();
        if (null != gmtStartTime) {
            DateTime dateTime = DateUtil.beginOfDay(gmtStartTime);
            queryWrapper.ge("GMT_DATE", dateTime);
        }
        if (null != gmtEndTime) {
            DateTime dateTime = DateUtil.endOfDay(gmtEndTime);
            queryWrapper.le("GMT_DATE", dateTime);
        }
        List<StatisticSitePageViewsPO> statisticSitePageViewsPOS = baseMapper.pageViewCount(queryWrapper);
        return statisticSitePageViewsPOS;
    }
}
